package com.kang.controller;

import com.kang.entity.Folder;
import com.kang.entity.FolderCarousel;
import com.kang.service.FolderCarouselService;
import com.kang.util.WebResponse;
import com.kang.vo.FolderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "轮播图接口")
@RestController
@RequestMapping("/admin/folderCarousel")
@Slf4j
public class FolderCarouselController {

    @Autowired
    private FolderCarouselService folderCarouselService;

    @ApiOperation("添加轮播图")
    @PostMapping("insertFolderCarousel")
    public WebResponse insertFolderCarousel(@RequestBody FolderCarousel folderCarousel) {
        try {
            return WebResponse.resSuccess("添加轮播图成功",folderCarouselService.insertFolderCarousel(folderCarousel));
        } catch (Exception ex) {
            log.error("添加轮播图失败",ex);
            return WebResponse.resFail("添加轮播图失败",null);
        }
    }


    @ApiOperation("删除轮播图")
    @PostMapping("deleteFolderCarousel")
    public WebResponse deleteFolderCarousel(@RequestBody FolderCarousel folderCarousel) {
        try {
            return WebResponse.resSuccess("删除轮播图成功",folderCarouselService.deleteFolderCarousel(folderCarousel));
        } catch (Exception ex) {
            log.error("删除轮播图失败",ex);
            return WebResponse.resFail("删除轮播图失败",null);
        }
    }


    @ApiOperation("分页查询轮播图")
    @GetMapping("getFolderCarouselPage")
    public WebResponse getFolderCarouselPage(FolderVo folderVo) {
        try {
            return WebResponse.resSuccess("分页查询轮播图成功",folderCarouselService.getFolderCarouselPage(folderVo));
        } catch (Exception ex) {
            log.error("分页查询轮播图失败",ex);
            return WebResponse.resFail("分页查询轮播图失败",null);
        }
    }


}
